package com.yhy.server.controller;

import com.yhy.domain.UserInfo;
import com.yhy.server.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户第一次登陆成功时保存用户详情
     *
     * 请求链接：/user/loginReginfo post
     *
     * 参数：jsonBody: UserInfo
     *      Authorization: token
     */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReinfo(@RequestBody UserInfo userInfo,
                                      @RequestHeader("Authorization") String token){
        return userService.saveUserInfo(userInfo,token);
    }

    /**
     * 用户第一次登陆成功时上传头像
     * @param token
     * @param headPhoto
     * @return
     */
    @PostMapping("/loginReginfo/head")
    public ResponseEntity loginReinfo(@RequestHeader("Authorization") String token,
                                      MultipartFile headPhoto) throws IOException {
        return userService.updateUserHead(headPhoto,token);
    }
}
